#include <iostream>

using namespace std;

int pic[5][5]=
{
    {0, 0, 0, 0, 1},
    {0, 1, 1, 0, 1},
    {0, 1, 0, 0, 1},
    {1, 1, 1, 0, 1},
    {1, 1, 0, 0, 1}
};

int idx[5][5] = {{0}};

void dfs(int i, int j, int cnt)
{
    if (i < 0 || i > 5 || j < 0 || j > 5)
    {
        return;
    }

    if (idx[i][j] > 0 || pic[i][j] != 1)
    {
        return;
    }

    idx[i][j] = cnt;
    for (int dr = -1; dr <= 1; dr++)
    {
        for (int dc = -1; dc <= 1; dc ++)
        {
            if (dr != 0 || dc != 0)
            {
                dfs(i + dr, j + dc, cnt);
            }
        }
    }
}

int main()
{
    int cnt = 0;
    for (int i = 0; i < 5; ++i)
    {
        for (int j = 0; j < 5; ++j)
        {
            if (0 == idx[i][j] && pic[i][j] == 1)
            {
                dfs(i, j, ++cnt);
            }
        }
    }
    cout << cnt << endl;
    return 0;
}
